//
//  HotRecommendCollectionReusableView.m
//  TravelFollowYourHeart
//
//  Created by 鲁万玺 on 2017/12/15.
//  Copyright © 2017年 Lwx. All rights reserved.
//

#import "HotRecommendCollectionReusableView.h"

#define btnTag 10000

@interface HotRecommendCollectionReusableView()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *height;

@property (weak, nonatomic) IBOutlet UIButton *btn1;
@property (weak, nonatomic) IBOutlet UIButton *btn2;
@property (weak, nonatomic) IBOutlet UIButton *btn3;
@property (weak, nonatomic) IBOutlet UIButton *btn4;
@property (weak, nonatomic) IBOutlet UIButton *btn5;
@property (weak, nonatomic) IBOutlet UIButton *btn6;
@property (weak, nonatomic) IBOutlet UIButton *btn7;

@property (weak, nonatomic) IBOutlet UIView *lineAnimationView;
@property (weak, nonatomic) IBOutlet UIButton *allBtn;
@property (weak, nonatomic) IBOutlet UIButton *myClosestBtn;
@property (weak, nonatomic) IBOutlet UIButton *scoringBtn;
@property (weak, nonatomic) IBOutlet UIButton *hotBtn;

@property (nonatomic, strong)UIView *lineView;

@end

@implementation HotRecommendCollectionReusableView

- (void)awakeFromNib {
    [super awakeFromNib];
    self.lineView = [[UIView alloc]init];
    self.lineView.backgroundColor = [UIColor themeColor];
    self.lineView.frame = CGRectMake(5, 45-3, SCREEN_WIDTH/4 -10, 3);
    [self.lineAnimationView addSubview:self.lineView];
    
    
    self.btn1.tag = btnTag+0;
    self.btn2.tag = btnTag+1;
    self.btn3.tag = btnTag+2;
    self.btn4.tag = btnTag+3;
    self.btn5.tag = btnTag+4;
    self.btn6.tag = btnTag+5;
    self.btn7.tag = btnTag+6;
    
    [self.btn7 setCornerRadius:25.0/2];
    [self.btn1 setCornerRadius:25.0/2];
    [self.btn2 setCornerRadius:25.0/2];
    [self.btn3 setCornerRadius:25.0/2];
    [self.btn4 setCornerRadius:25.0/2];
    [self.btn5 setCornerRadius:25.0/2];
    [self.btn6 setCornerRadius:25.0/2];
    
    [self.btn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [self.btn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [self.btn3 setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [self.btn4 setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [self.btn5 setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [self.btn6 setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [self.btn7 setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    
    self.btn1.selected = YES;
}

- (IBAction)chooseList:(UIButton *)sender
{
    if (sender.selected) {
        return;
    }
    
    NSInteger i = 0;
    if (sender == self.allBtn)
    {
        i = 0;
    }
    else if (sender == self.myClosestBtn)
    {
        i = 1;
    }
    else if (sender == self.scoringBtn)
    {
        i = 2;
    }
    else
    {
        i = 3;
    }
    
    if ([self.delegate respondsToSelector:@selector(getButtonNumWithI:)]) {
        
        [self.delegate getButtonNumWithI:[[NSNumber numberWithInteger:i] intValue]];
    }
    self.allBtn.selected = NO;
    self.myClosestBtn.selected = NO;
    self.scoringBtn.selected = NO;
    self.hotBtn.selected = NO;
    
    sender.selected = YES;
    WS(ws)
    
    [UIView animateWithDuration:0.5 animations:^{
        ws.lineView.x = SCREEN_WIDTH/4 *i +5;
    }];
}
- (IBAction)chooseTJ:(UIButton *)sender
{
    if (sender.selected)
    {
        return;
    }
    for (int i = btnTag; i<=btnTag+6; i++)
    {
        UIButton *button = [self viewWithTag:i];
        if (button == sender)
        {
            button.selected = YES;
            button.backgroundColor = [UIColor themeColor];
            if ([self.delegate respondsToSelector:@selector(getSignNumWith:)]) {
                [self.delegate getSignNumWith:i - btnTag];
            }

        }
        else
        {
            button.selected = NO;
            button.backgroundColor = [UIColor whiteColor];
        }
    }
}

- (void)setIsHiddenTitle:(BOOL)isHiddenTitle
{
    _isHiddenTitle = isHiddenTitle;
    if (_isHiddenTitle)
    {
        self.height.constant = 0;
    }
}

@end
